(function(app){
	app
		.controller("content_34_inputCtrl",["$scope","$state","myFactory",'$stateParams',"$q",'$timeout','$location','$http','$ionicHistory',function($scope,$state,myFactory,$stateParams,$q,$timeout,$location,$http,$ionicHistory){
			//参数定义、接收
			var itemId = $stateParams.changeTypeId;//变更项目ID
			var chdrnum01 =  $stateParams.chdrnum01; //保单号
			var chdrcoy = $stateParams.chdrcoy; //保单公司号码
			var policyData;//保单详情
			var itemData;//用于接收初始化查询initContentItem的内容，里面存在各种各样的内容，比如item02_1
			var searchParam = $stateParams.searchParam;
			var initFlag = false;//检测标志，在初始化函数完成后，会被置为true
			var token=sessionStorage.getItem("token");
			//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190606 start
			var isPolicyValue;//是否存在未领取的生存金和年金
			//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190606 end
			
			//绑定参数到页面
			$scope.chdrnum01 = chdrnum01;
			$scope.declarationFlag = false;//声明标志，默认为false
			$scope.readFlag = false;//阅读协议标志，默认为false

			$scope.data = {
				checkFlag: false,
				wayVal: null,
				wayList: [
					{
						id: '0011',
						name: '经济或家庭原因'
					},
					{
						id: '0012',
						name: '过期'
					}
				],
			};

			/**********************************************初始化函数begin****************************************************/
				//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "itemId-token-timestamp";
				var signStr="itemId="+itemId+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'input/initContentItem.action',
					params: {'itemId': itemId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						itemData = response.data.data.modelMap;
						$scope.item34 = itemData.item34;
						var item34 = itemData.item34;
						//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190606 start
						isPolicyValue = itemData.isPolicyValue;
						if ( isPolicyValue == "Y" ){
							$('#show').show();
						}
						//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190606 end
						
						$scope.declaration = item34.declaration;
						$scope.invalidCause = item34.invalidCause;
						
						//下拉选择初始化
						//如果存在缓存，则采用缓存中记录
						if($scope.invalidCause!=null && $scope.invalidCause!=undefined && $scope.invalidCause !=""){
							$("#invalidCause").val($scope.invalidCause);//设置为缓存中的选项
							$scope.invalidCause = $scope.invalidCause;
						}else{
							//否则采用默认
							$("#invalidCause").val("01");//经济或家庭原因
							$scope.invalidCause = "01";
						}
						
						$scope.changeInvalidCause();
						if($scope.declaration==0){
							$("#declarationFlag").removeAttr("checked");
						}else if($scope.declaration==1){
							$("#declarationFlag").attr("checked","checked");
						}

						initFlag=true;//标识初始化成功
						myFactory.loadingHide();
					}else{
						myFactory.loadingHide();
						myFactory.alert("","初始化查询变更项内容失败!","info");
					}
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
			}
			/**********************************************初始化函数end****************************************************/

			//重新受理
			$scope.renew = function(){
				myFactory.renew();
			}
			//退出移动保全
			$scope.exit = function(){
				myFactory.exit();
			}
			//返回上一页
			$scope.goBack = function(){
				myFactory.goBack();
			}
			//关闭遮罩
			$scope.overwindowClose = function(){
				$(".overwindow").hide();
				$(".overmodal").hide();
			}
			//保单详情弹框
			$scope.showPolicyDetail = function(){
				modal('open','policyModalOn34Input','overwindowOn34Input','policyCloseXOn34Input');
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-chdrcoy-token-timestamp";
				var signStr="chdrnum="+chdrnum01+"&chdrcoy="+chdrcoy+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//初始化时候查询保单详情
				$http({
					method: 'GET',
					url: app.domain + 'query/restFindPolicyDetail.action',
					params: {'chdrnum': chdrnum01,'chdrcoy': chdrcoy,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						policyData = response.data.data;
						$scope.policyData = policyData;
						$scope.policyData.ptdate01=myFactory.DateTools($scope.policyData.ptdate01);
					}
				}, function errorCallback(response) {
					myFactory.alert("","初始化查询订单详情失败!","info");
				});
			}
			//保单详情弹窗关闭函数
			$scope.policyCancelOn34Input = function(){
				modal('close','policyModalOn34Input','overwindowOn34Input','policyCloseXOn34Input');
			}

			//客户须知
			$scope.tipOpen = function(){
				modal('open','tip_model','overwindowOn34Input');
			}
			$scope.closeTip = function(){
				modal('close','tip_model','overwindowOn34Input');
			}

			//改变下拉框
			$scope.changeInvalidCause = function(){
				var options = $("#invalidCause option:selected");
				console.log("id:"+options.val());
				console.log("val:"+options.text());
//				$scope.actdivamtMsg = options.text();
				$("#actdivamtMsg").val(options.text());
			}
			//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 start
			//改变投保人和被保人关系的下拉框
			$scope.changePeoRelation = function(){
				var options = $('#peopleRelationCause option:selected');
				$('#peopleRelationInput').val(options.text());
			} 
			//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 end
			//页面同意阅读协议复选框部分
			$scope.changeReadFlag = function(){
				$scope.readFlag = !$scope.readFlag;
				console.log($scope.readFlag);
			}

			$scope.declarCheckBox = function(){
				$scope.declarationFlag = !$scope.declarationFlag;
				if($scope.declarationFlag==true){
					$scope.declaration = "1";
				}else{
					$scope.declaration = "0";
				}
			}

			//下一步
			$scope.nextStep = function(){
				myFactory.loadingShow();//显示加载圈
				if(!initFlag){
					myFactory.alert("","初始化时失败，请返回上一步重试","info");
					myFactory.loadingHide(); // 隐藏转菊
                                        return;
                                 }
				//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 start
				if ( isPolicyValue == "Y" ){
					var resonPeoRelationInput = $('#peopleRelationInput');
					if ( resonPeoRelationInput.val() == '' ||resonPeoRelationInput.val() == undefined ){ 
						myFactory.alert("","请选择投被保人关系","info");
						myFactory.loadingHide(); 
						return;
					}
					
					var resonPeoRelation = $('#peopleRelationCause');
					if (resonPeoRelation.val() == '6' ){
						myFactory.alert("","投保人与被保险人非直系亲属关系，需由被保险人的监护人提出一同申请，请通过书面办理。","info");
						myFactory.loadingHide(); 
						return;
					}
				}
				//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 end
				var readFlag = $scope.readFlag;
				if(readFlag==false){
					myFactory.alert("","请同意并阅读《申请须知》","info");
					myFactory.loadingHide(); // 隐藏转菊
					return;
				}
				// S2019022607440-NT状态无退费的申请增加拦截  add by csf 2019-4-11 start
				var spillPayFee	= $scope.item34.spillPayFee				//	溢缴保费   1+8
				var cashBonus =  $scope.item34.cashBonus        	//	现金红利本息
				var cashAccount= $scope.item34.cashAccount      	//	现金价值及账户值   3+4
				var lifeMoney =  $scope.item34.lifeMoney        	//	生存金本息
				var specialBonus=$scope.item34.specialBonus     	//	特别红利
				var others    =  $scope.item34.others           	//	其它      
				var tf = Number(spillPayFee)+Number(cashBonus)+Number(cashAccount)
						+Number(lifeMoney)+Number(specialBonus)+Number(others)
				if(tf == 0){
					myFactory.alert("","本保单无退费，无须申请终止合同结清变更","info");
					myFactory.loadingHide(); 
					return;
				}
				// S2019022607440-NT状态无退费的申请增加拦截 add by csf  2019-4-11 end
				
				
				//var invalidCause = $("#invalidCause").val();
				var declaration = $scope.declaration;
				var options = $("#invalidCause option:selected");
				var invalidCause = options.val(); //选择原因
				console.log(declaration);
				console.log(invalidCause);

				var item={
					"itemId":itemId,
					"declaration":declaration,
					//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 start
					"invalidCause":invalidCause,
					"peoRelation":$('#peopleRelationCause').val()
					//S2019051508554《反洗钱监管-官微、移动保全增加核实投被保险关系功能需求》 add by csf 20190527 end
				}

				$ionicHistory.clearCache().then(function(){
					myFactory.loadingHide(); // 隐藏转菊
					$state.go('content_check_main',{
						itemId:itemId,
						item:item,
						chdrnum01:chdrnum01,
						chdrcoy:chdrcoy,
						searchParam:searchParam
					});
				})
			}

		}]);

		//指针弹窗
		app.directive('infoid',function(){
			return {
				restrict: 'EA',		//指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
				templateUrl: 'html/input/content_base_info.html'+app.clearCache,
				replace: true,		//设置解析后，DOM声明的指令是否消失
				link: function(scope,element,attrs){  //链接函数负责注册DOM事件和更新DOM,
					console.log('指令完成');
				}
			}
		});

})(app)